Skip to content

Limit the size of served files #834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jun 15, 2020
Merged

Conversation

pietroalbini
Copy link
Member

This PR limits how big the files we serve from docs.rs are, to avoid OOMs. The current limit is 5MB, but that can be changed by tweaking a constant in the source code.

This PR adds limits when downloding the files from S3 and the database, and when decompressing previously downloaded files. For now the user will see a "resource not found" error page, but a dedicated page can be created in the future.

This PR also refactors compression a bit to better enable testing. It's best to review the PR commit-by-commit.

r? @jyn514

Comment on lines +172 to +173
let alg = DEFAULT_COMPRESSION;
let content = compress(file, alg)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of setting a variable to DEFAULT_COMPRESSION instead of using it directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put DEFAULT_COMPRESSION in a variable as that makes changing the function to accept the algorithm as a parameter easier in the future. I'm not too attached to that though, I can surely change this.

@Nemo157
Copy link
Member

Nemo157 commented Jun 12, 2020

LGTM

@pietroalbini
Copy link
Member Author

Addressed all the review comments, and changed the maximum size to 50MB for non-HTML files.

I think this is ready to go, I'll follow up with a PR that does a couple refactorings and then adds a test for File::from_path. One last check @Kixiron @jyn514?

@pietroalbini
Copy link
Member Author

Nevermind, also added the final test.

}

impl Config {
pub fn from_env() -> Result<Self, Error> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is that over time we'll move more of the environment variables here, instead of being spread out over the codebase? I like it, it makes things much easier to test as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's the goal!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely support that, having a concrete storage of env vars in one place would be fantastic

@jyn514
Copy link
Member

jyn514 commented Jun 15, 2020

Looks good to me modulo nits.

@pietroalbini
Copy link
Member Author

@jyn514 addressed the nits.

I also updated how tests can override configuration values to this:

env.override_config(|config| {
   config.key = value;
});

Using the closure allows to change the default configuration for tests in the future without having to update the base config in each test that overrides it.

@jyn514
Copy link
Member

jyn514 commented Jun 15, 2020

Looks great, thanks!

@jyn514 jyn514 merged commit 1155c74 into rust-lang:master Jun 15, 2020
@pietroalbini pietroalbini deleted the limit-size branch June 15, 2020 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants